package la.bbs558.controller.admin;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import la.bbs558.aop.valid.Check;
import la.bbs558.aop.valid.Valid;
import la.bbs558.controller.base.Result;
import la.bbs558.entity.vo.BbsClassActiveVO;
import la.bbs558.entity.params.BbsClassActivePage;
import la.bbs558.entity.params.BbsClassActiveParams;
import la.bbs558.satoken.StpAdminUtil;
import la.bbs558.service.BbsClassActiveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: Shanks
 * @date: 2023/12/15 10:45
 * @desc:
 */
@RestController
@RequestMapping("/admin/active")
@SaCheckRole(value = { "admin" },type = StpAdminUtil.TYPE)
@Check
public class ActiveController {
    @Resource
    private BbsClassActiveService activeService;

    /**
     * 添加活动
     * @param params 活动参数
     */
    @PostMapping("add")
    @SaIgnore
    public Result<?> add(@Valid @RequestBody BbsClassActiveParams params) {
        activeService.add(params);
        return Result.success();
    }

    /**
     * 活动详情
     * @param activeId 活动id
     */
    @GetMapping("detail")
    @SaIgnore
    public Result<?> detail(Long activeId) {
        BbsClassActiveVO res = activeService.detail(activeId);
        return Result.success(res);
    }

    /**
     * 活动列表
     * @param page 分页参数
     */
    @GetMapping("list")
    @SaIgnore
    public Result<?> list(BbsClassActivePage page) {
        activeService.list(page);
        return Result.success(page);
    }

    /**
     * 编辑活动
     * @param bbsClassActive 活动
     */
    @PostMapping("update")
    @SaIgnore
    public Result<?> update(@RequestBody BbsClassActiveParams bbsClassActive) {
        activeService.update(bbsClassActive);
        return Result.success(bbsClassActive);
    }

    /**
     * 删除活动
     * @param activeId 活动id
     */
    @PostMapping("delete")
    @SaIgnore
    public Result<?> delete(Long activeId) {
        activeService.delete(activeId);
        return Result.success();
    }
}
